package com.infoland.afanmall.model.zhongChou.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutCompat;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.infoland.afanmall.R;
import com.infoland.afanmall.base.util.LogKit;
import com.infoland.afanmall.base.util.ToolsKit;
import com.infoland.afanmall.model.zhongChou.entity.ZhongChouResponse;

import java.math.BigDecimal;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author 王永吉
 * @date 2018/7/12 9:43
 */
public class ListFragmentAdapter extends BaseQuickAdapter<ZhongChouResponse.ObjectBean.ListBean, BaseViewHolder> {

    @BindView(R.id.zhc_img)
    AppCompatImageView zhcImg;
    @BindView(R.id.zhc_txt)
    AppCompatTextView zhcTxt;
    @BindView(R.id.zhc_pro_bar)
    ProgressBar zhcProBar;
    @BindView(R.id.zhc_price)
    AppCompatTextView zhcPrice;
    @BindView(R.id.zhc_pro_txt)
    AppCompatTextView zhcProTxt;
    @BindView(R.id.zhc_txt2)
    TextView zhcTxt2;
    @BindView(R.id.order_info_block3)
    LinearLayoutCompat orderInfoBlock3;

    public ListFragmentAdapter(int layoutResId, @Nullable List<ZhongChouResponse.ObjectBean.ListBean> data) {
        super(R.layout.zhong_chou_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ZhongChouResponse.ObjectBean.ListBean item) {
        ButterKnife.bind(this, helper.itemView);
        ToolsKit.setImgView(item.getF_url(), zhcImg);
        zhcTxt.setText(item.getCf_description());
        List<ZhongChouResponse.ObjectBean.ListBean.LevelsBean> levels = item.getLevels();
        ZhongChouResponse.ObjectBean.ListBean.LevelsBean levelsBean = levels.get(0);
        zhcPrice.setText("￥" + levelsBean.getCfl_amount());
        double cf_target_amount = item.getCf_target_amount();//目标金额
        double cf_now_amount = item.getCf_now_amount();//已筹金额
        double cf_now_count = item.getCf_now_count();//参加人数
        BigDecimal twoNumber = ToolsKit.getTwoNumber(cf_now_amount, cf_target_amount);
        int jindu = twoNumber.intValue();
        zhcProTxt.setText(jindu + "%");
        zhcProBar.setProgress(jindu);
        if (this.getData().size() == (helper.getAdapterPosition() + 1)) {
            LogKit.E("aaaa ---->   ", "  " + helper.getAdapterPosition());
            ToolsKit.addMargin(helper.itemView, 0, 0, 0, SizeUtils.dp2px(20));
        }
        orderInfoBlock3.setOnClickListener(v -> {
            zhongChouListener.click(helper.getAdapterPosition());
        });
    }

    ZhongChouListener zhongChouListener;

    public void setZhongChouListener(ZhongChouListener zhongChouListener) {
        this.zhongChouListener = zhongChouListener;
    }

    public interface ZhongChouListener {
        void click(int adapterPosition);
    }
}